//
//  HMUserAccessModel.swift
//  swift微博项目
//
//  Created by huodian on 16/9/26.
//  Copyright © 2016年 huodian. All rights reserved.
//

import UIKit

class HMUserAccessModel: NSObject,NSCoding {

    var access_token:String?
    
    var uid :String?
    
    var avatar_large:String?
    
    var name : String?
    
    var expires_in: Int = 0 {
        
        didSet {
            
            timeOut_in = Date(timeIntervalSinceNow: Double(expires_in))
            
        }
        
    }
    
    var timeOut_in: Date?
    
    
    init(dict:[String:Any]) {
        super.init()
        
        self.setValuesForKeys(dict)
        
    }
    
    override func setValue(_ value: Any?, forUndefinedKey key: String) { }
    
    
    func encode(with aCoder: NSCoder) {
        
        aCoder.encode(access_token, forKey: "access_token")
        
        aCoder.encode(uid, forKey: "uid")
        
        aCoder.encode(name, forKey: "name")
        
        aCoder.encode(avatar_large, forKey: "avatar_large")
        
        aCoder.encode(timeOut_in, forKey: "timeOut_in")
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        
         access_token=aDecoder.decodeObject(forKey: "access_token") as? String
        
         uid=aDecoder.decodeObject(forKey: "uid") as? String
        
        name=aDecoder.decodeObject(forKey: "name") as? String
        
        avatar_large=aDecoder.decodeObject(forKey: "avatar_large") as? String
        
        timeOut_in = aDecoder.decodeObject(forKey: "timeOut_in") as? Date
        
    }
    
    
    
    
}
